#include<iostream>
#include<fstream>
#include"contacts.pb.h"
using namespace std;
using namespace google::protobuf;
using namespace c_contacts;


void PrintCon(c_contacts::PeopleContacts& con)
{
    for(int i=0;i<con.cont_size();i++)
    {
        cout<<"-------------联系人"<<i+1<<"--------------------"<<endl;
        const c_contacts::PeopleInfo& people = con.cont(i);
        cout<<"姓名："<<people.name()<<endl;
        cout<<"年龄："<<people.age()<<endl;
        for(int j=0;j<people.phione_size();j++)
        {
            const c_contacts::PeopleInfo_Phone& phone = people.phione(j);
            cout<<"电话"<<j+1<<":"<<phone.number();
            cout<<"  ("<<phone.PhoneType_Name(phone.type())<<")"<<endl;
        }
       const Reflection* reflection = PeopleInfo::GetReflection();
       const UnknownFieldSet& unknowSet = reflection->GetUnknownFields(people);

       for(int j=0;j<unknowSet.field_count();j++)
       {
        const UnknownField& fild = unknowSet.field(j);
        cout<<"未知字段"<<j+1<<":"<<"字段编号："<<fild.number()<<"类型："<<fild.type();
        switch(fild.type())
        {
            case UnknownField::Type::TYPE_VARINT:
                cout<<" 值:"<<fild.varint()<<endl;
                break;
            case UnknownField::Type::TYPE_LENGTH_DELIMITED:
                cout<<" 值:"<<fild.length_delimited()<<endl;
                break;
        }
       }
    }
}
int main()
{

    c_contacts::PeopleContacts contacts;
    fstream input("../server/test.bin",ios::in|ios::binary);
    if(!contacts.ParseFromIstream(&input))
    {
        cerr<<"parse error"<<endl;
        input.close();
        return 1;
    }
    PrintCon(contacts);
    return 0;
}